package com.example.app.components.MyModalBottomSheet.MyModalBottomSheetDateTimePicker

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.app.components.MySpacer.MySpacer
import com.example.app.components.MySwitch.MySwitch
import com.example.app.components.MyText.MyText
import com.example.app.ui.theme.my_description_color
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class MyDateTimeSwitchBtnState {
    var _checked = MutableStateFlow<Boolean>(false)
    var checked = _checked.asStateFlow()
    fun flowUpdate_checked(value: Boolean) {
        _checked.update {
            value
        }
    }
}
//选择时间，或者日期
@Composable
fun MyDateTimeSwitchBtn(
        myDateTimeSwitchBtnState: MyDateTimeSwitchBtnState
) {
    var checked = myDateTimeSwitchBtnState.checked.collectAsState()
    Row(
        horizontalArrangement = Arrangement.Center,
        verticalAlignment = Alignment.CenterVertically
    ) {
        MyText(
            text = "日期",
            style = if (!checked.value) MaterialTheme.typography.titleMedium.copy(color = MaterialTheme.colorScheme.primary) else MaterialTheme.typography.bodySmall.copy(color = my_description_color)
        )
        MySpacer(modifier = Modifier.width(6.dp))
        MySwitch(checked = checked.value,
            onCheckedChange = {
                myDateTimeSwitchBtnState.flowUpdate_checked(it)
            })
        MySpacer(modifier = Modifier.width(6.dp))
        MyText(
            text = "时间",
            style = if (checked.value) MaterialTheme.typography.titleMedium.copy(color = MaterialTheme.colorScheme.primary) else MaterialTheme.typography.bodySmall.copy(color = my_description_color)
        )
    }
}